package com.zhkj.crawl.bean;

import com.alibaba.fastjson.JSON;
import com.zhkj.crawl.config.StringPool;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Data
@Slf4j
public class CrawAmzParams {
    private String plat = "亚马逊";
    private String tb = "";
    private String site = "";
    private int proxyCount = 400;
    private int noProxyCount = 200;
    private Integer threadCount = null;
    private boolean proxy = true;


    private final static CrawAmzParams DEFAULT_VAL = new CrawAmzParams();
    public static CrawAmzParams init(String param){
        try {
            if(StringUtils.isNotBlank(param)){
                CrawAmzParams params = JSON.toJavaObject(JSON.parseObject(param), CrawAmzParams.class);
                if(StringUtils.isBlank(params.getTb())){
                    params.setTb(StringPool.EMPTY);
                }
                if(StringUtils.isBlank(params.getSite())){
                    params.setSite(StringPool.EMPTY);
                }
                return params;
            }
        }catch (Exception e){
            log.error("CrawAmzParams参数错误 {}", param);
        }
        return DEFAULT_VAL;
    }
}
